/**
 * 
 */
package onibus;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import br.com.sistransporte.transite.onibus.controller.OnibusFacade;
import br.com.sistransporte.transitedto.onibus.OnibusDTO;
import br.com.src.dto.abstractdto.AbstractDTO;
import br.com.src.dto.requisicao_retorno.RequisicaoServico;
import br.com.src.dto.requisicao_retorno.RetornoServico;
import br.com.src.utilidades.Utilidades;

/**
 * Classe que representa
 *
 *
 * @author Nelson Luis da Silva Junior <nelson.jr13@hotmail.com@>
 * @since 4 de Jul de 2013 17:05:30
 * @version 1.0
 */
@ContextConfiguration( locations = { "classpath:rootTeste-context.xml", "classpath:rootTesteLog-context.xml" } )
@RunWith( SpringJUnit4ClassRunner.class )
public final class OnibusTeste{

//	@Test
	public void filtrar() throws Throwable {
		RequisicaoServico requisicaoServico = new RequisicaoServico( "teste", new OnibusDTO() );
		RetornoServico retornoServico = OnibusFacade.getInstance().filtrar( requisicaoServico );

		if ( !Utilidades.isNuloOuVazio( retornoServico.erro ) ) {
			throw retornoServico.erro;
		}

		for ( AbstractDTO abstractsDTOs : retornoServico.getDtosRetorno() ) {
			System.out.println( abstractsDTOs );
		}
	}

	@Test
	public void inserir() throws Throwable{
		RequisicaoServico requisicaoServico = new RequisicaoServico( "nelson" , new OnibusDTO( null,"50","BLK-2222","Onibus Devargarinho", "true" ) );
		RetornoServico retornoServico = OnibusFacade.getInstance().inserir( requisicaoServico );

		filtrar();

		if( !Utilidades.isNuloOuVazio( retornoServico.erro )){
			throw retornoServico.erro;
		}
	}

	//@Test
	public void alterar() throws Throwable{
		RequisicaoServico requisicaoServico = new RequisicaoServico( "nelson" , new OnibusDTO("1","60","BLK-6156","Onibus Ligeirinho", "true"));
		RetornoServico retornoServico = OnibusFacade.getInstance().alterar( requisicaoServico );

		filtrar();

		if( !Utilidades.isNuloOuVazio( retornoServico.erro )){
			throw retornoServico.erro;
		}
	}

	//@Test
	public void delete() throws Throwable{
		// Consultando
		RequisicaoServico requisicaoServicoFilter = new RequisicaoServico( "teste", new OnibusDTO("3") );
		RetornoServico retornoServicoFilter = OnibusFacade.getInstance().filtrar( requisicaoServicoFilter );
		if ( !Utilidades.isNuloOuVazio( retornoServicoFilter.erro ) ) {
			throw retornoServicoFilter.erro;
		}
		for ( AbstractDTO abstractsDTOs : retornoServicoFilter.getDtosRetorno() ) {
			System.out.println( abstractsDTOs );
		}
		
		
		RequisicaoServico requisicaoServico = new RequisicaoServico( "gabriel" , retornoServicoFilter.getSingleDTO() );
		RetornoServico retornoServico = OnibusFacade.getInstance().excluir( requisicaoServico );

		filtrar();

		if( !Utilidades.isNuloOuVazio( retornoServico.erro )){
			throw retornoServico.erro;
		}
	}

	
	}
